package com.ny.wlw;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class TestConnection7 {

        private static  final  String URL="jdbc:mysql://localhost:3306?usersdb";
        private  static  final  String usename="root";
        private  static  final  String password="123456";


        public static void main(String[] args) throws SQLException {
            Connection conn = DriverManager.getConnection(URL,usename,password);
            String sql ="insert into users(number,username,password,age)";
            PreparedStatement pstm = conn.prepareStatement(sql);
            Scanner scanner=new Scanner(System.in);
            System.out.println("请输入员工编号");
            String number =scanner.next();
            System.out.println("请输入用户名");
            String username = scanner.next();
            System.out.println("请输入密码");
            String password = scanner.next();
            System.out.println("请输入年龄");
            int age = scanner.nextInt();
            pstm.setString(1,number);
            pstm.setString(2,username);
            pstm.setString(3,password);
            pstm.setInt(4,age);

            int i =pstm.executeUpdate();
            if (i>0){
                System.out.println("员工信息添加成功");
            }
            else {
                System.out.println("员工信息添加失败");
            }
        }
}
